package com.qf.controller;

import com.qf.domain.Answers;
import com.qf.service.AnswersService;
import com.qf.vo.ResultVO;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.validation.Valid;
import java.util.Date;

@Controller
@ResponseBody
@RequestMapping("/answers")
public class AnswersController {
    @Autowired
    private AnswersService answersService;
    int i=0;
    @PostMapping("/insertanswers")
    public ResultVO insertAnswers(@RequestParam ("id")Integer id,@RequestParam("ansContent")String ansContent){
        ResultVO resultVO=new ResultVO();
        System.out.println(id);
        Answers answers=new Answers(0, ansContent, new Date(),id );
            int i=answersService.insertAnswers(answers);
            if (i!=1){
                resultVO.setMsg("回答没有成功");
                resultVO.setCode(500);
                return resultVO;
            }else {
                return resultVO;
            }

    }
}
